﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FlashCards.Model;

namespace FlashCards.WebApp.Utils
{
    public class DevelopmentNewsUtils
    {
        public static List<DevelopmentNews> GetLatestNews()
        {
            using(var context = new FlashCardsEntities())
            {
                var news = context.DevelopmentNewsSet.OrderByDescending(x => x.DevelopmentNewsDate)
                    .Take(6)
                    .ToList();

                return news;
            }
        }
        
        public static void AddNews(string title, string message)
        {
            using (var context = new FlashCardsEntities())
            {
                var news = new DevelopmentNews()
                {
                    DevelopmentNewsDate = DateTime.Now,
                    DevelopmentNewsTitle = title,
                    DevelopmentNewsMessage = message
                };

                context.DevelopmentNewsSet.AddObject(news);
                context.SaveChanges();
            }
        }
    }
}